from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import urlfetch
from StringIO import StringIO 

import BeautifulSoup
import re

class MainPage(webapp.RequestHandler):
  def get(self):
	    self.response.headers['Content-Type'] = 'text/plain'
	    url = "http://www.jobrapido.it" + "/?w=erp&l=lombardia"
	    result = urlfetch.fetch(url)
            body=result.content
	    soup = BeautifulSoup.BeautifulSoup(body)
	    annunci = soup.findAll('a',id=re.compile('SearchResultSlot'))
	    for annuncio in annunci:
                annuncio_link = unicode(annuncio['href'])
		self.response.out.write(annuncio_link)

#	    if result.status_code == 200:
#		self.response.out.write(result.content)

application = webapp.WSGIApplication(
                                     [('/', MainPage)],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()



